﻿using System.Data;

namespace LBSoft.Common.DotNetExt
{

    public static class ExtDataTable
    {
        /// <summary>
        /// 判断表中是否包含指定列
        /// </summary>
        /// <param name="columnNames">列名</param>
        /// <returns></returns>
        public static bool HasColumns(this DataTable source, params string[] columnNames)
        {
            if (source == null || columnNames == null || columnNames.Length == 0)
            {
                return false;
            }
            foreach (string columnName in columnNames)
            {
                bool flag = false; //标志是否找到该列
                foreach (DataColumn col in source.Columns)
                {
                    if (col.ColumnName.Trim().ToLower() == columnName.Trim().ToLower())
                    {
                        flag = true;
                        break;
                    }
                }
                if(!flag) //若没找到其中一列
                {
                    return false;
                }
            }
            return true;
        }
    }
}
